package com.project.common;

import java.sql.SQLException;

public class PuduException extends Exception {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * DB操作异常
	 */
	public static final String EX_DB_OPERATION = "EX_DB_OPERATION";
	/**
	 * DB连接异常
	 */
	public static final String EX_DB_CONNECTION = "EX_DB_CONNECTION";
	/**
	 * 传入的异常
	 */
	private Throwable rootCause = null;
	/**
	 * 异常类型
	 */
	private String pudu_exception_type = "";
	/**
	 * 如果是DB异常，把異异常状态和信息赋给这两个数
	 */
	private int errorCode = 0;
	private String sqlState = null;
	/**
	 * 其它的异常信息
	 */
	private String exMessage = "";

	/**
	 * description:構造函數，把其它異常封裝成FMSException
	 * 
	 * @param ex_type
	 *            異常類型
	 * @param rootCause
	 *            異常
	 */
	public PuduException(String ex_type, Throwable rootCause) {
		super(rootCause);
		this.rootCause = rootCause;
		this.pudu_exception_type = ex_type;
	}

	public PuduException(String ex_type, String exMessage, Throwable rootCause) {
		super(rootCause);
		this.rootCause = rootCause;
		this.pudu_exception_type = ex_type;
		this.exMessage = exMessage;
		if (PuduException.EX_DB_OPERATION.equals(ex_type)
				&& rootCause instanceof SQLException) {
			SQLException sqle = (SQLException) rootCause;
			this.errorCode = sqle.getErrorCode();
			this.sqlState = sqle.getSQLState();
		}

	}

	public Throwable getRootCause() {
		return rootCause;
	}

	public void setRootCause(Throwable rootCause) {
		this.rootCause = rootCause;
		
	}

	public String getPudu_exception_type() {
		return pudu_exception_type;
	}

	public void setPudu_exception_type(String pudu_exception_type) {
		this.pudu_exception_type = pudu_exception_type;
	}

	public int getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(int errorCode) {
		this.errorCode = errorCode;
	}

	public String getSqlState() {
		return sqlState;
	}

	public void setSqlState(String sqlState) {
		this.sqlState = sqlState;
	}

	public String getExMessage() {
		return exMessage;
	}

	public void setExMessage(String exMessage) {
		this.exMessage = exMessage;
	}

}
